#include "delay.h"
#include "sys.h"
#include "usart.h"	 
#include "can.h" 
#include "oled.h"
#include "Display.h"
#include "IIC.h"
#include "adc.h"
#include "stm32f10x_adc.h"
#include "stm32f10x_flash.h"
#include "stmflash.h"
#include "stm32f10x_dma.h"
#include "DMA.h"

extern uint8_t DMA_flag;
/*****************************************************
** @函数名：NVIC_Configuration
** @描述  ：无
** @参数  ：无
** @返回值：配置DMA
*****************************************************/
void DMA_Configuration(void)
{
  DMA_InitTypeDef DMA_InitStructure;	
  NVIC_InitTypeDef NVIC_InitStructure;

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);                         //开启DMA1时钟
	
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);	

  DMA_DeInit(DMA1_Channel1);
  DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;                 //ADC1->DR;
  DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValue;            //ADC_ConvertedValue里面存放的是转换出来的AD值
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;                          //内存作为DMA传输的目的
  DMA_InitStructure.DMA_BufferSize = 200;                                     //DMA通道的DMA缓存大小
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;            //外设地址寄存器不变
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;                     //内存地址寄存器DMA_MemoryInc_Disable：不变DMA_MemoryInc_Enable:递增
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; //DMA数据为半字
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;         //DMA到外部存储器也为半字
  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;                             //循环周期
  DMA_InitStructure.DMA_Priority = DMA_Priority_High;                         
  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
  DMA_Init(DMA1_Channel1, &DMA_InitStructure);
    
  DMA_Cmd(DMA1_Channel1, ENABLE);                   /*使能DMA通道1*/
  
  DMA_ITConfig(DMA1_Channel1,DMA_IT_TC,ENABLE);	    /*使能DMA传输完成中断*/
	
  NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn; 
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; 
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4; 
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 
  NVIC_Init(&NVIC_InitStructure);          // Enable the DMA1 Interrupt 	
}
/*****************************************************
** @函数名：DMA1_Channel1_IRQHandler
** @描述  ：无
** @参数  ：无
** @返回值：DMA1通道存储满，产生中断
*****************************************************/
void DMA1_Channel1_IRQHandler(void)
{
	if(DMA_GetITStatus(DMA1_IT_TC1) != RESET)
   {
	 DMA_flag = 1;   
     DMA_ClearITPendingBit(DMA1_IT_TC1);
   }
}


